use anyhow::{Error, Result};
use libloading::{library_filename, Library, Symbol};
use std::{
  env::current_exe,
  sync::{Arc, Mutex},
  thread,
  time::Duration,
};

fn main() -> Result<()> {
  //unsafe { rmwlib::run() };
  let exe = current_exe()?;
  let pwd = exe.parent().unwrap();
  let so_path = pwd.join(library_filename("rmwlib"));
  unsafe {
    let so = Arc::new(Library::new(so_path)?);
    let run: Symbol<unsafe extern "C" fn()> = so.get(b"run")?;
    let so2 = so.clone();
    thread::spawn(move || {
      let run2: Symbol<unsafe extern "C" fn()> = so2.get(b"run").unwrap();
      run2();
    });
    run();
  };
  Ok(())
}
